<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>学习笔记</title>
  </head>
  <body>
    <button id="btn">测试按钮</button>
    <!-- <script src="./index.js"></script>
    <script src="./my-bind.js"></script>
    <script>
      const module = {
        vale: 'hhh',
        getName() {
          console.log(this.vale);
        },
      };
      const unBindGetName = module.getName;
      const bindGetName = unBindGetName.myBind(1);
      bindGetName(2, 3);
    </script> -->
    <!-- <script src="./src/my-flat.js"></script> -->
    <!-- <script src="./src/linked-list.js"></script> -->
    <script src="./src/binary-search-tree.js"></script>
    <script>
      // 7, 3, 5, 4, 9, 8, 2, 12, 6，1
      const binarySearchTree = new BinarySearchTree()
      binarySearchTree.insert(7)
      binarySearchTree.insert(3)
      binarySearchTree.insert(5)
      binarySearchTree.insert(4)
      binarySearchTree.insert(9)
      binarySearchTree.insert(8)
      binarySearchTree.insert(2)
      binarySearchTree.insert(12)
      binarySearchTree.insert(6)
      binarySearchTree.insert(1)

      const root = JSON.parse(JSON.stringify(binarySearchTree.root))
      const newTree = binarySearchTree.removeNode(root, 5)
      console.log(newTree, 'root2')
      const node = binarySearchTree.searchNode(root, 1)
      console.log(node)
      binarySearchTree.preOrder(root)
    </script>
    <!-- <script>
      const btn = document.getElementById('btn');
      btn.addEventListener('click', () => {
        setTimeout(() => {
          console.log(5);
        });
        new Promise((resolve, reject) => {
          console.log(3);
          resolve(7);
        }).then((res) => {
          console.log(res);
        });
        console.log(1);
      });
      btn.addEventListener('click', () => {
        setTimeout(() => {
          console.log(6);
        });
        new Promise((resolve, reject) => {
          console.log(4);
          resolve(8);
        }).then((res) => {
          console.log(res);
        });
        console.log(2);
      });
      btn.click();
      // js 触发 click 事件，会先执行完全部监听事件后回收，然后触发代码中的微任务. setTimeout 用于验证是否进入下一轮。
      // 由结果可知,宏任务 setTimeout 进行到下一轮
      // 简单记忆可把两个函数合并为同一个执行函数
      // 输出结果为 3 1 4 2 7 8 5 6

      // 如果是由用户操作 DOM 事件触发，则先执行完第一个回调后执行第二个回调。但 setTimeout 宏任务还是在下一轮执行
      // 输出结果为 3 1 7 4 2 8 5 6
    </script> -->
  </body>
</html>
